<template>
  <div class="mv-container">
    <div class="mv-wrap">
      <h3 class="title">mv详情</h3>
      <!-- mv -->
      <div class="video-wrap">
        <video

          controls
          :src="url"
        ></video>
      </div>
      <!-- mv信息 -->
      <div class="info-wrap">
        <div class="singer-info">
          <div class="avatar-wrap">
            <img :src="mvMsg.cover" alt="" />
          </div>
          <span class="name">{{mvMsg.artistName}}</span>
        </div>
        <div class="mv-info">
          <h2 class="title">{{mvMsg.name}}</h2>
          <span class="date">发布：{{mvMsg.publishTime}}</span>
          <span class="number">播放：{{mvMsg.playCount}}次</span>
          <p class="desc">
           {{mvMsg.desc}}
          </p>
        </div>
      </div>
      <!-- 精彩评论 -->
      <div class="comment-wrap">
        <p class="title">精彩评论<span class="number">({{total}})</span></p>
        <div class="comments-wrap">
          <div class="item" v-for="(item,index) in hotCom" :key="index">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}：</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div class="re-content" v-if="item.beReplied.length!==0">
                <span class="name">{{item.beReplied[0].user.nickname}}：</span>
                <span class="comment">{{item.beReplied[0].content}}</span>
              </div>
              <div class="date">{{item.time|timeShow}}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 最新评论 -->
      <div class="comment-wrap">
        <p class="title">精彩评论<span class="number">({{total}})</span></p>
        <div class="comments-wrap">
          <div class="item" v-for="(item,index) in comment" :key="index">
            <div class="icon-wrap">
              <img :src="item.user.avatarUrl" alt="" />
            </div>
            <div class="content-wrap">
              <div class="content">
                <span class="name">{{item.user.nickname}}：</span>
                <span class="comment">{{item.content}}</span>
              </div>
              <div class="re-content" v-if="item.beReplied.length!==0">
                <span class="name">{{item.beReplied[0].user.nickname}}：</span>
                <span class="comment">{{item.beReplied[0].content}}</span>
              </div>
              <div class="date">{{item.time|timeShow}}</div>
            </div>
          </div>
        </div>
      </div>
      <!-- 分页器 -->
      <el-pagination
        @current-change="handleCurrentChange"
        background
        layout="prev, pager, next"
        :total="total"
        :current-page="page"
        :page-size="20"
        :limit="limit"
      >
      </el-pagination>
    </div>
    <!-- 推荐的区域 -->
    <div class="mv-recommend">
      <h3 class="title">相关推荐</h3>
      <div class="mvs">
        <div class="items">
          <div class="item" @click="getMV(item.id)" v-for="(item,index) in recommondMV" :key="index">
            <div class="img-wrap">
              <img :src="item.cover" alt="" />
              <span class="iconfont icon-play"></span>
              <div class="num-wrap">
                <div class="iconfont icon-play"></div>
                <div class="num">{{item.playCount|num}}</div>
              </div>
              <span class="time">{{item.duration|time}}</span>
            </div>
            <div class="info-wrap">
              <div class="name">{{item.name}}</div>
              <div class="singer">{{item.artistName}}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {getMvs,getSmiMvs,getMvMsg,getMvCom} from '@/api/getMv'
export default {
  name: 'mv',
  data() {
    return {
      // 总条数
      total: 0,
      // 页码
      page: 1,
      // 页容量
      limit: 20,
      url:'',
      // 相关推荐的mv数据
      recommondMV:[],
      mvMsg:{},
      // 热门评论
      hotCom:[],
      // 精彩[评论]
      comment:[],
      offset:0,
    };
  },
  created() {
    this.getMv()
    // 获取相似的mv列表
    this.getSmiMvs()
    // 获取歌曲的信息
    this.getMvMsg()
    // 获取评论信息
    this.getCom()
  },
  methods: {
    // 获取mv的评论信息
    async getCom(){
      const {data}=await getMvCom({
        id:this.$route.query.id,
        limit:20,
        offset:this.offset
      })
      // 获取总评论页数
      this.total=data.total
      // 获取热门评论
      this.hotCom=data.hotComments
      // 获取总评论信息
      this.comment=data.comments


    },
    // 获取歌曲的信息列表
   async getMvMsg(){
     const {data:{data}}=await getMvMsg(this.$route.query.id)
     this.mvMsg=data

   },
    // 点击推荐区域获取mv列表
    async getMV(id){
      this.$router.push({
        name:"mv",
        query:{
          id
        }
      })

    },
    // 获取相似的mv列表
    async getSmiMvs(){
      const {data}=await getSmiMvs(this.$route.query.id)
      this.recommondMV=data.mvs
    },
    // 获取mv的信息
    async getMv(){
        const {data:{data}}=await getMvs(this.$route.query.id)
        this.url=data.url
    },
    handleCurrentChange(val) {
     this.page=val
     this.offset=(this.page-1)*20
    //  调用接口数据
    this.getCom()
    },

  },
  watch: {
    "$route":function(){
      this.getMv()
    // 获取相似的mv列表
    this.getSmiMvs()
    // 获取歌曲的信息
    this.getMvMsg()
    // 获取评论信息
    this.getCom()
    }
  },

};
</script>

<style></style>
